<?php
require_once('include/inc_database.php');
require_once('include/inc_useraccount.php');

// Open DB connection.
$dbobj = new DatabaseObject();
$dbobj->OpenConnection();

$auth = new UserAccount();

if ($_POST['redirect_to'] != "")
	$redirect_to = $_POST['redirect_to'];
elseif ($_GET['redirect_to'] != "")
	$redirect_to = $_GET['redirect_to'];
else
	$redirect_to = "./";

// Log in.
if ($_POST['username'] != "") {
	if (!$auth->Login($_POST['username'], $_POST['password'])) {
		echo "<p>Error: " . $auth->error_string;
		exit();
	}
	setcookie("test", "testvalue2", time()+(3600*24*360));
	Header("Location: " . $redirect_to);
	exit();
}

// Log out.
if ($_POST['logout'] == "on" || $_GET['logout'] == "on") {
	$auth->Logout();
	Header("Location: " . $redirect_to);
	exit();
}
?>


<html>
<head>
<title>Login - <?=SiteConst('site_name')?></title>

<link rel="shortcut icon" href="images/favicon.gif" type="image/x-icon">
<meta name="viewport" content="width=700"/>

<style type="text/css">
	@import url('rec.css?<?=$CSS_VERSION?>');

</style>

<script type="text/javascript">

</script>

</head>
<body>

<div id="main">

<h1 style="margin-bottom:25px;">
	<a href="./"><img src="images/logo02b.jpg" align="middle" border="0"/></a>
	<?=SiteConst('site_name')?> - Login
</h1>



<form name="f" action="" method="post">
	<input type="hidden" name="redirect_to" value="<?=htmlentities($redirect_to)?>">

	<p>
		In order to make recommendations or comments, you have to log in.
		<br/>Don't have a user name?  <a href="createuser1.php">Create an account</a>
	</p>

	<br/>
	<table>
	<tr>
		<td>Username:</td>
		<td>
			<input type="text" name="username" value="" style="width:100px;">
		</td>
	</tr>
	<tr>
		<td>Password:</td>
		<td>
			<input type="password" name="password" value="" style="width:100px;">
		</td>
	</tr>
	<tr>
		<td></td>
		<td>
			<input type="submit" name="submit" value="Log in">
		</td>
	</tr>
	</table>


</form>

</div>

</body>
</html>
